﻿#include "hotelcertmodel.h"

HotelCertModel::HotelCertModel(QObject *parent)
    : QAbstractTableModel(parent)
{
    m_header << "酒店编号" << "酒店名称"  << "酒店星级" << "酒店价格" << "商家姓名"<< "联系电话" << "房间总数" << "提交时间" << "酒店位置";
}


int HotelCertModel::columnCount(const QModelIndex &parent) const
{
    return m_header.size();
}
int HotelCertModel::rowCount(const QModelIndex &parent) const
{
    return GlobalVars::g_hotelManageList->size();
}
QVariant HotelCertModel::data(const QModelIndex &index, int role) const
{
    if(!index.isValid())
        return QVariant();

    if(role == Qt::DisplayRole)
    {
        QString userID = GlobalVars::g_hotelManageList->at(index.row()).getUser();
        switch(index.column())
        {
            case 0: return  GlobalVars::g_hotelManageList->at(index.row()).getHotel();
            case 1: return  GlobalVars::g_hotelManageList->at(index.row()).getName();
            case 2: return  GlobalVars::g_hotelManageList->at(index.row()).getStar();
            case 3: return  GlobalVars::g_hotelManageList->at(index.row()).getLowPrice();
            case 4: return  GlobalVars::g_hotelManageList->at(index.row()).getUser();
            case 5: return  GlobalVars::g_hotelManageList->at(index.row()).getPhone();
            case 6: return  GlobalVars::g_hotelManageList->at(index.row()).getTotalHouse();
            case 7:
            {
                QStringList strList = GlobalVars::g_hotelManageList->at(index.row()).getState().split("*");
                if (strList.size() >= 2)
                {
                    return strList.at(1);
                }
                return GlobalVars::g_hotelManageList->at(index.row()).getState();
            }
            case 8: return  GlobalVars::g_hotelManageList->at(index.row()).getLocation();
            default: return QVariant();
        }
    }
    return QVariant();
}
QVariant HotelCertModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if(role==Qt::DisplayRole && orientation==Qt::Horizontal)
    {
        return m_header[section];
    }
    return QAbstractTableModel::headerData(section,orientation,role);
}

void HotelCertModel::refrushModel()
{
    beginResetModel();
    endResetModel();
}

const QString& HotelCertModel::getHotelID(int index)
{
    return GlobalVars::g_hotelManageList->at(index).getHotel();
}
